package com.zuipin.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;

import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/** 
* @ClassName: ConstantsUtil 
* @author wuyicheng
* @time 2017年3月28日下午4:20:40 
*/
public class ConstantsUtil {
	///////////////////////////删除标志/////////////////////////
	/*
	 * 已删除
	 */
	public static final short	DEL_FLAG_YES_1	= 1;
	/*
	 * 未删除
	 */
	public static final short	DEL_FLAG_NO_0	= 0;
	/*
	 * 返回结果
	 */
	public static final String RETURN_RESULT="returnResult";
	
	/**
	 * 短信验证码
	 */
	public static final String SMS_CODE="smsCode";
	
	/**
	 * 抽奖返回SKU
	 */
	public static final String PRO_SKU = "proSku";
	
	/*
	 * 抽奖返回描述
	 */
	public static final String DESCRIPTION = "description";
	
	/**
	 * 可用抽奖次数
	 */
	public static final String CAN_USE_NUMS = "canUseNums";
	
	/**
	 * 默认查询数量
	 */
	public static final int DEFAULT_SEARCH_NUMS = 20;
	
	/**
	 * 返回成功
	 */
	public static final String SUCCESS="success";
	
	/**
	 * 醉品系统ID
	 */
	public static final Long ZUIPIN_SYS_2=2L;
	
	/**
	 * 运费8折
	 */
	public static final BigDecimal FREIGHT_DISCOUNT_8=new BigDecimal(0.80);
	
	/**
	 * 运费不打折
	 */
	public static final BigDecimal FREIGHT_DISCOUNT_10=new BigDecimal(1.00);
	
	/**
	 * 免邮金额
	 */
	public static final BigDecimal NO_FREIGHT_59 =new BigDecimal(59.00);
	/**
	 * 默认支付方式
	 */
	public static final String PAYMETHOD_DEFAULT_1 = "1";
	/**
	 * 默认配送方式
	 */
	public static final String DELIVERY_METHOD_DEFAULT_1 = "1";
	/**
	 * 不配送的地方省编码(台湾省,香港特别行政区,澳门特别行政区)
	 */
	public static final String LIMIT_PRIVOICE = "710000,810000,820000";
	
	/**
	 * 规则是否可用
	 */
	public static final String IS_CAN_USE = "isCanUse";
	/*
	 * 检验规则返回错误码
	 */
	public static final String ERROR_CODE = "errorCode";
	/*
	 * 分隔符逗号
	 */
	public static final String COMMA = ",";
	/*
	 * 派发红包
	 */
	public static final String SEND_REDPACKET_FLAG="sendRedPacketFlag";
	/*
	 * 系统确认收货
	 */
	public static final String RECEIPT_NAME_SYSTEM="系统确认收货";
	/*
	 * 用户确认收货
	 */
	public static final String RECEIPT_NAME_MEMBER="用户确认收货";
	/*
	 * 积分抵扣比例50:1
	 */
	public static final Integer ONE_TO_FIFTH=50;
	/*
	 * 默认收货地址（收银）
	 */
	public static final Long DEFAULT_ADDRESS_ID=-1L;
	/*
	 * 分类树的根节点
	 */
	public static final Long TREE_ROOT_CODE = 3L;
	/**
	 * 将参数组装成符合junit的map对象
	 *
	 * @Title: paramReflect 
	 * @author: wuyicheng
	 * @date: 2017年3月30日上午8:59:15 
	 * @param model 
	 *             实体类
	 * @param className 
	 *             对象名
	 * @return
	 * @throws NoSuchMethodException
	 * @throws SecurityException
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 * @throws InvocationTargetException
	 * @return: MultiValueMap<String,String>
	 * @throws
	 */
	public static MultiValueMap<String, String> paramReflect(Object model, String objectName)
			throws NoSuchMethodException, SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
		Field[] fields = model.getClass().getDeclaredFields(); //获取实体类的所有属性，返回Field数组  
		if (fields != null && fields.length > 0) {
			for (Field field : fields) {//遍历所有属性
				String name = field.getName();//获取属性的名字	
				//				System.out.println("----属性名:" + name);
				String attributeName = name.substring(0, 1).toUpperCase() + name.substring(1); //将属性的首字符大写，方便构造get，set方法
				//String type = field.getGenericType().toString();//获取属性的类型
				//				System.out.println("--------类型:" + type);
				Method method = null;
				try {
					method = model.getClass().getMethod("get" + attributeName);
				} catch (Exception e) {
					System.out.println("不存在这个get方法");
				}
				if (method != null) {
					Object value = (Object) method.invoke(model);
					if (value != null) {
						//System.out.println("------------值:" + String.valueOf(value));
						map.add(objectName + "." + name, String.valueOf(value));
					} else {
						//System.out.println("------------值:" + null);
					}
				}
			}
		}
		return map;
	}
}
